package onjava.advance.ch01.sec10;

import java.util.EnumMap;

public enum Category {
    // 投入钱币
    MONEY(Input.NICKEL, Input.DIME, Input.QUARTER, Input.DOLLAR),
    // 选择商品
    ITEM_SELECTION(Input.TOOTHPASTE, Input.CHIPS, Input.SODA, Input.SOAP),
    // 退出交易
    QUIT_TRANSACTION(Input.ABORT_TRANSACTION),
    // 关闭机器
    SHUT_DOWN(Input.STOP);

    private Input[] values;

    Category(Input... types) {
        values = types;
    }

    private static EnumMap<Input, Category> categories = new EnumMap<>(Input.class);

    static {
        for (Category c : Category.class.getEnumConstants()) {
            for (Input type : c.values) {
                categories.put(type, c);
            }
        }
    }

    public static Category categorize(Input input) {
        return categories.get(input);
    }
}
